package com.qdu.web.controller.bussiness;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qdu.common.annotation.Log;
import com.qdu.common.core.controller.BaseController;
import com.qdu.common.core.domain.AjaxResult;
import com.qdu.common.enums.BusinessType;
import com.qdu.bussiness.domain.BusTicketPurchase;
import com.qdu.bussiness.service.IBusTicketPurchaseService;
import com.qdu.common.utils.poi.ExcelUtil;
import com.qdu.common.core.page.TableDataInfo;

/**
 * 购票记录Controller
 * 
 * @author qdu
 * @date 2022-03-06
 */
@RestController
@RequestMapping("/bussiness/purchase")
public class BusTicketPurchaseController extends BaseController
{
    @Autowired
    private IBusTicketPurchaseService busTicketPurchaseService;

    /**
     * 查询购票记录列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusTicketPurchase busTicketPurchase)
    {
        startPage();
        List<BusTicketPurchase> list = busTicketPurchaseService.selectBusTicketPurchaseList(busTicketPurchase);
        return getDataTable(list);
    }

    /**
     * 导出购票记录列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:purchase:export')")
    @Log(title = "购票记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusTicketPurchase busTicketPurchase)
    {
        List<BusTicketPurchase> list = busTicketPurchaseService.selectBusTicketPurchaseList(busTicketPurchase);
        ExcelUtil<BusTicketPurchase> util = new ExcelUtil<BusTicketPurchase>(BusTicketPurchase.class);
        util.exportExcel(response, list, "购票记录数据");
    }

    /**
     * 获取购票记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:purchase:query')")
    @GetMapping(value = "/{purchaseId}")
    public AjaxResult getInfo(@PathVariable("purchaseId") Long purchaseId)
    {
        return AjaxResult.success(busTicketPurchaseService.selectBusTicketPurchaseByPurchaseId(purchaseId));
    }

    /**
     * 新增购票记录
     */
    @PreAuthorize("@ss.hasPermi('bussiness:ticket:purchase')")
    @Log(title = "购票记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusTicketPurchase busTicketPurchase)
    {
        return busTicketPurchaseService.insertBusTicketPurchase(busTicketPurchase);
    }

    /**
     * 修改购票记录
     */
    @PreAuthorize("@ss.hasPermi('bussiness:purchase:edit')")
    @Log(title = "购票记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusTicketPurchase busTicketPurchase)
    {
        return toAjax(busTicketPurchaseService.updateBusTicketPurchase(busTicketPurchase));
    }

    /**
     * 删除购票记录
     */
    @PreAuthorize("@ss.hasPermi('bussiness:purchase:remove')")
    @Log(title = "购票记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseIds)
    {
        return toAjax(busTicketPurchaseService.deleteBusTicketPurchaseByPurchaseIds(purchaseIds));
    }

    /**
     * 核销门票
     * @param purchaseId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('bussiness:purchase:verify')")
    @Log(title = "核销门票", businessType = BusinessType.UPDATE)
    @GetMapping("/verify/{purchaseId}")
    public AjaxResult verifyTicketPurchase(@PathVariable Long purchaseId){
        return busTicketPurchaseService.verifyTicketPurchase(purchaseId);
    }
}
